<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        /* let a;
        ({a} = {a:1})//加括号成为表达式，否则报错，{a}当成一个块级作用域
        console.log(a);//1 */

        /* let a1 = [1, 2, 3], obj = {};
        //模式匹配
        [obj.a, obj.b, obj.c] = a1;
        console.log(obj);//{a: 1, b: 2, c: 3} */
       
        /*  //（）的使用：用le、vart声明 用（）报错
        let [a] = [1];
        //let [(a)] = [1];
        let {a: b} = {}//b=undefined
        //let {(a): b} = {}
        //let {a: (b)} = {} */
       
        /* //函数传参相当于变量声明与初始化赋值，声明方式使用let方式，用（）报错
        //function fn((z)){}//报错
        function fn([z]){}//参数解构
        function fn([(z)]){}//报错
        function fn(([z])){}//报错 */

        /* //数组是特殊的对象{0:1, 2: 1, 3: 2,  length: 3}
        let arr = [1, 2, 3];
        let {'0': first, 1: second, 2: third} = arr
        console.log(first, second, third);//1 2 3 */

        //window.b
        /* [(b)] = [1];
        console.log(b);//1
        ([b]) = [1];
        console.log(b);//报错，匹配规则，模式，（）本质是表达式
        ({a:(b)={}}) //b= {}
        [(a.b)] = [3]//a.b=3 */
        
        //let is not defined let、var声明后面使用（）
        /* let a = 'x', b = 'y', obj = {};
        ({a: obj[a+b]} = {a: 2});//加（）形成表达式，否则{}视为块级作用域后面=报错
        console.log(obj);//{xy:2} */

        /* let a = 1, b = 2;
        [a, b] = [b, a];
        console.log(a, b); */
        //变量解构本质是变量赋值
        //模式匹配可以匹配同源属性
        // let {a: x, a: y} = {a: 1};
        // console.log(x, y);

        //函数参数解构赋值
        /* function fn([x,y]){
            console.log(x,y);
        }
        fn([1,2]);
        fn()//报错
        fn([])//undefined undefined */

        /* function fn({x,y}){
            console.log(x, y);
        }
        fn({x: 1,y: 2}) */

        /* function fn({x = 10} = {}, {y} = {y: 10}){
            console.log(x, y);
        }
        fn()// 10 10
        fn({},{}) //10 undefined */
        /* ({x=10} = {});
        ({y} = {y:10}); */

       /*  //解构的隐式转换
        //字符串转换为类数组
        let [a, b, c, d, e] = 'hello';
        console.log(a, b, c, d, e);//h e l l o
        let {length: len} = 'hello';
        console.log(len);//5
        //数字隐式转换
        let {toString: s} = 123;
        console.log(s === Number.prototype.toString);// true
        //boolean包装类
        let {toString: l} = false;
        console.log(l === Boolean.prototype.toString);// true
        //undefined,null不能隐式转换
        let {prop} = undefined;
        console.log(prop);// 报错
        let {prop} = null;
        console.log(prop);// 报错
        //所以fn（）不赋值相当于undefined不能隐式转换所以报错，{}能隐式转换 */





















    </script>
</body>
</html>